<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div class="app">
        <my-div></my-div>
        <my-div></my-div>
        <my-p></my-p>
        <my-d></my-d>
        <my-span></my-span>
    </div>

    <template id="od">
        <div>
            <h1>你好啊{{tit_1}}</h1>
        </div>
    </template>
    <script>
        Vue.component("myDiv", {
            template: "<div><p>{{msg}}{{count}}</p><button @click='add' >{{count}}</button><button @click='add' >{{count}}</button></div>",
            data() { //组件data必须是一个函数，必须有返回值，形成独立的闭包变量作用范围 保护内部的数据不受外面的数据的污染
                return {
                    count: 1,
                    msg: "自定义组件",
                }
            },
            methods: {
                add() {
                    this.count += 1
                }
            }
        })

        //
        obj1 = {
            template: "<h1>{{tit}}</h1>",
            data() {
                return {
                    tit: "component"
                }
            }
        }
        Vue.component("myP", obj1)
            //

        Vue.component("myD", {
            template: "#od",
            data() {
                return {
                    tit_1: "锚点"
                }
            }
        })
        const vm = new Vue({
            data: {
                msg: "nishishaguan"
            },
            components: {
                mySpan: {
                    template: "<h1>我是局部注册的组件-{{msg}}</h1>",
                    data() {
                        return {
                            msg: "你是傻瓜"
                        }
                    }
                }
            }
        }).$mount(".app")
    </script>
</body>

</html>